I have a PowerPoint presentation with some simple graphs
and text, nothing fancy. I am attempting to write code
that will update the graphs. I could easily use Excel to
update the data and then link the presentation to it, but
I'm hoping for a solution that just does the work in
PowerPoint. I've searched the Internet and help files and
can not find what I need. I did find this code from
Microsoft's site. It will create a word document, create a
graph, and populate the graph with data. However, I did
not find a version of this code for PowerPoint. Could
someone with more VB knowledge than I (which is just about
everybody) jimmy this code so that it will just change the
data in an existing PowerPoint slide?
thanx
Dim oWordApp As Word.Application
Dim oWordDoc As Word.Document
Dim oShape As Word.Shape
Dim oGraphChart As Graph.Chart
'Create a new document in Word.
Set oWordApp = CreateObject("Word.Application")
oWordApp.Visible = True
Set oWordDoc = oWordApp.Documents.Add
'Add some text to the document.
oWordDoc.Content.Text = "This is my new chart:"
'Embed a chart on the document.
Set oShape = oWordDoc.Shapes.AddOLEObject( _
Left:=100, Top:=100, Width:=350, Height:=200, _
ClassType:="MSGraph.Chart", DisplayAsIcon:=False)
Set oGraphChart = oShape.OLEFormat.object
With oGraphChart
'Format the embedded chart.
.ChartArea.Font.Size = 8
.Application.Update
.ChartType = xl3DBarClustered
.HasTitle = True
.ChartTitle.Text = "Sales per Product"
.ChartTitle.Font.Size = 12
.Axes(xlValue).HasTitle = True
.Axes(xlValue).AxisTitle.Caption = "Dollars ($)"
.ChartArea.AutoScaleFont = False
'Add data for the chart to the DataSheet in MSGraph.
With .Application.DataSheet
.Cells.Clear
'Add the chart row labels.
.Cells(2, 1).Value = "Widgets"
.Cells(3, 1).Value = "Gadgets"
.Cells(4, 1).Value = "Gizmos"
'Add the chart column labels.
.Cells(1, 2).Value = "1999"
.Cells(1, 3).Value = "2000"
'Add data to the chart.
Dim r As Integer, c As Integer
For r = 2 To 4
For c = 2 To 3
.Cells(r, c).Value = Rnd() * 100000
Next
Next
End With
.Application.Update 'Update the changes
.Application.Quit 'and deactivate the chart.
End With
'Clean up.
Set oGraphChart = Nothing
Set oShape = Nothing
Set oWordDoc = Nothing
Set oWordApp = Nothing
Dim oPPApp As PowerPoint.Application
Dim oSlide As PowerPoint.Slide
Dim oShape As PowerPoint.Shape
Dim oGraphChart As Graph.Chart
Set oPPApp = CreateObject("PowerPoint.Application")
oPPApp.Visible = True
oPPApp.Presentations.Add withwindow:=msoTrue
'ActiveWindow.View.GotoSlide
Index:=ActivePresentation.Slides.Add(Index:=1,
Layout:=ppLayoutBlank).SlideIndex
oPPApp.ActivePresentation.Slides.Add 1, ppLayoutChart
Set oSlide = oPPApp.ActivePresentation.Slides(1)
Set oShape = oSlide.Shapes.AddOLEObject(Left:=120#,
Top:=110#, Width:=480#, Height:=320#,
ClassName:="MSGraph.Chart", Link:=msoFalse)
Set oGraphChart = oShape.OLEFormat.object
With oGraphChart
'Format the embedded chart.
.ChartArea.Font.Size = 8
.Application.Update
.ChartType = xl3DBarClustered
.HasTitle = True
.ChartTitle.Text = "Sales per Product"
.ChartTitle.Font.Size = 12
.Axes(xlValue).HasTitle = True
.Axes(xlValue).AxisTitle.Caption = "Dollars ($)"
.ChartArea.AutoScaleFont = False
With .Application.DataSheet
.Cells.Clear
'Add the chart row labels.
.Cells(2, 1).Value = "Widgets"
.Cells(3, 1).Value = "Gadgets"
.Cells(4, 1).Value = "Gizmos"
'Add the chart column labels.
.Cells(1, 2).Value = "1999"
.Cells(1, 3).Value = "2000"
Dim r As Integer, c As Integer
For r = 2 To 4
For c = 2 To 3
.Cells(r, c).Value = Rnd() * 100000
Next
Next
End With
.Application.Update 'Update the changes
.Application.Quit 'and deactivate the chart.
End With
Set oGraphChart = Nothing
Set oShape = Nothing
Set oWordDoc = Nothing
Set oWordApp = Nothing
End Sub
>.
>